package com.roast.util;

import java.util.List;
import com.roast.domain.*;

public class ArrayListUtil {

    public static boolean isParticipant(List<UserData> list, UserData user) {
        long idUser = user.getUserID();
        for (int i = 0; i < list.size(); i++) {
            long idList = list.get(i).getUserID();
            if (idUser == idList) {
                return true;
            }
        }
        return false;
    }

    public static boolean removeParticipantByID(long userID, List<UserData> list) {
        for (int i = 0; i < list.size(); i++) {
            long id = list.get(i).getUserID();
            if (userID == id) {
                list.remove(i);
                return true;
            }
        }
        return false;
    }

    public static Address getAddressByUserID(long userID, List<Address> addressArray) {
        for (int i = 0; i < addressArray.size(); i++) {
            Address address = addressArray.get(i);
            long addressByUserID = address.getAddressByUser().getUserID();
            if (userID == addressByUserID) {
                return address;
            }
        }
        return null;
    }

    public static boolean isParticipantAddressStar(long userID, List<Address> addressArray) {
        Address address = getAddressByUserID(userID, addressArray);
        return address != null;
    }
}
